#include "function_base_test.h"
#include <gtest/gtest.h>

namespace viml {

/**
 * 基本函数调用测试
 */
class FunctionCallTest : public FunctionCallTestBase {
protected:
    void SetUp() override {
        FunctionCallTestBase::SetUp();
    }
};

// FC-001: 测试无参数函数定义和调用
TEST_F(FunctionCallTest, SimpleFunctionCall) {
    std::string source = R"(
function greet()
    echo "Hello, World!"
endfunction

greet()
)";
    
    compileAndExecute(source, "SimpleFunctionCall");
}

// FC-002: 测试带参数函数定义和调用
TEST_F(FunctionCallTest, FunctionWithParameters) {
    std::string source = R"(
function greet(name)
    echo "Hello, " .. name
endfunction

greet("World")
)";
    
    compileAndExecute(source, "FunctionWithParameters");
}

// FC-003: 测试函数返回值
TEST_F(FunctionCallTest, FunctionWithReturnValue) {
    std::string source = R"(
function add(a, b)
    return a + b
endfunction

let result = add(3, 4)
echo result
)";
    
    compileAndExecute(source, "FunctionWithReturnValue");
}

// FC-004: 测试函数嵌套调用
TEST_F(FunctionCallTest, NestedFunctionCall) {
    std::string source = R"(
function add(a, b)
    return a + b
endfunction

function multiply(a, b)
    return a * b
endfunction

let result = multiply(add(2, 3), 4)
echo result
)";
    
    compileAndExecute(source, "NestedFunctionCall");
}

// FC-005: 测试递归函数调用
TEST_F(FunctionCallTest, RecursiveFunctionCall) {
    std::string source = R"(
function factorial(n)
    if n <= 1
        return 1
    endif
    return n * factorial(n - 1)
endfunction

let result = factorial(5)
echo result
)";
    
    compileAndExecute(source, "RecursiveFunctionCall");
}

// FC-006: 测试函数内局部变量作用域
TEST_F(FunctionCallTest, FunctionLocalScope) {
    std::string source = R"(
let global_var = "global"

function test_scope()
    let local_var = "local"
    echo global_var  // 应该能访问全局变量
    echo local_var   // 应该能访问局部变量
endfunction

test_scope()
)";
    
    compileAndExecute(source, "FunctionLocalScope");
}

// FC-007: 测试函数内全局变量访问
TEST_F(FunctionCallTest, FunctionGlobalAccess) {
    std::string source = R"(
let global_var = "global_value"

function access_global()
    echo global_var
endfunction

access_global()
)";
    
    compileAndExecute(source, "FunctionGlobalAccess");
}

// FC-008: 测试多个参数传递
TEST_F(FunctionCallTest, MultipleParameters) {
    std::string source = R"(
function concat_three(a, b, c)
    return a .. b .. c
endfunction

let result = concat_three("Hello", " ", "World")
echo result
)";
    
    compileAndExecute(source, "MultipleParameters");
}

// FC-009: 测试数值计算函数
TEST_F(FunctionCallTest, NumericCalculation) {
    std::string source = R"(
function calculate(a, b, c)
    return (a + b) * c - 5
endfunction

let result = calculate(10, 5, 2)
echo result
)";
    
    compileAndExecute(source, "NumericCalculation");
}

// FC-010: 测试空函数（无参数无返回值）
TEST_F(FunctionCallTest, EmptyFunction) {
    std::string source = R"(
function empty_func()
endfunction

empty_func()
)";
    
    compileAndExecute(source, "EmptyFunction");
}

} // namespace viml